﻿#region imports

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Globalization;
using Codeplex.ODataTFS.Model.Entities;
using Codeplex.ODataTFS.Model.Serialization;

#endregion

namespace Codeplex.ODataTFS.Model.Repositories
{
	public class LinkRepository
	{
		private readonly TFSLinkProxy _proxy;

		public LinkRepository(TFSLinkProxy proxy)
		{
			_proxy = proxy;
		}

		//[RepositoryBehavior(HandlesFilter = true)]
		//TODO: add filtering support that makes its way to wiql
		public IEnumerable<Link> GetLinksByWorkItem(string id)
		{
			var workItemId = 0;
			if (!int.TryParse(id, NumberStyles.Integer, CultureInfo.InvariantCulture, out workItemId))
			{
				throw new ArgumentException("The id parameter must be numeric", "workItemId");
			}

			return _proxy.GetLinksByWorkItem(workItemId);
		}

		public Link GetOne(string id)
		{
			throw new DataServiceException(501, "Not Implemented", "", "en-US", null);
		}

		public IEnumerable<Link> GetAll()
		{
			throw new DataServiceException(501, "Not Implemented", "The 'Link' collection cannot be enumerated as a root collection. It should depend on a WorkItem. (e.g. /WorkItems(12345)/Links)", "en-US", null);
		}
	}
}
